package com.spring.shops.model.result;
import lombok.Data;

import java.io.Serializable;

//统一响应体
@Data
public class ServerResponseEntityVoid<T> implements Serializable {
    private String code="00000";
    private String msg;
    private T data;
    private String version="mall4j.v230424";
    private Integer timestamp;
    private String sign;
    private boolean success=true;
    private boolean fail=false;
    //登录成功带token的响应的方法
    public static <T> ServerResponseEntityVoid<T> LoginSuccess(T data){
        ServerResponseEntityVoid<T> result = new ServerResponseEntityVoid<>();
        result.setData(data);
        return result;
    }
    //带数据的成功响应的方法
    public static <T> ServerResponseEntityVoid<T> success(T data) {
        ServerResponseEntityVoid<T> result = new ServerResponseEntityVoid<>();
        result.setData(data);
        return result;
    }
    //不带数据的成功响应的方法
    public static ServerResponseEntityVoid success() {
        ServerResponseEntityVoid result = new ServerResponseEntityVoid();
        return result;
    }
    //不带数据的失败响应的方法
    public static ServerResponseEntityVoid error() {
        ServerResponseEntityVoid result = new ServerResponseEntityVoid();
        result.setFail(true);
        result.setSuccess(false);
        result.setMsg("信息错误");
        return result;
    }
    public static ServerResponseEntityVoid error(String code,String msg) {
        ServerResponseEntityVoid result = new ServerResponseEntityVoid();
        result.setFail(true);
        result.setSuccess(false);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
